package com.zego.wawaji.ui.store.car.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zego.wawaji.R;
import com.zego.wawaji.base.log.PToast;
import com.zego.wawaji.base.module.ModuleMgr;
import com.zego.wawaji.third.image.ImageLoader;
import com.zego.wawaji.ui.bean.wawa.WawaJi;

import java.util.List;

/**
 * 推荐商品列表
 * Created by Su on 2018/1/8.
 */
public class StoreRecommendAdapter extends RecyclerView.Adapter<StoreRecommendAdapter.ViewHolder> {
    private Context context;
    private LayoutInflater mLayoutInflater;
    private List<WawaJi> mRoomList;

    public StoreRecommendAdapter(Context context, List<WawaJi> roomList) {
        mLayoutInflater = LayoutInflater.from(context);
        this.context = context;
        mRoomList = roomList;
    }

    public void setList(List<WawaJi> roomList) {
        this.mRoomList = roomList;
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mLayoutInflater.inflate(R.layout.item_recommend_list, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final WawaJi wawaji = mRoomList.get(position);
        holder.itemLayout.setLayoutParams(new RelativeLayout.LayoutParams((ModuleMgr.getAppMgr().getScreenWidth() - 40) / 2, ViewGroup.LayoutParams.WRAP_CONTENT));
        ImageLoader.loadCenterCrop(context, wawaji.getPicUrl(), holder.goodsImg);

        holder.goodsImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PToast.showShort("" + wawaji.getNickName() + ", " + wawaji.getWwTypeId());
            }
        });

        holder.store_car.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PToast.showShort(wawaji.getNickName() + "加入购物车成功");
            }
        });

        if (position == 0) {
            holder.store_title.setText("开始的那份快乐士大夫金龙卡降低 似的咖啡碱离开 克里斯蒂JFK i 坷拉似的咖啡碱 时代科技发展框架就立刻i空间克隆大师");
            holder.store_price.setText("200");
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView goodsImg;
        private RelativeLayout store_car, itemLayout;
        private TextView store_price, store_title;

        public ViewHolder(final View itemView) {
            super(itemView);
            goodsImg = (ImageView) itemView.findViewById(R.id.goods_img);
            store_car = (RelativeLayout) itemView.findViewById(R.id.store_car);
            store_price = (TextView) itemView.findViewById(R.id.store_price);
            store_title = (TextView) itemView.findViewById(R.id.store_title);
            itemLayout = (RelativeLayout) itemView.findViewById(R.id.cv_item);
        }
    }

    @Override
    public int getItemCount() {
        return mRoomList == null ? 0 : mRoomList.size();
    }
}
